package str;

import java.util.Arrays;

/**
 * @ Author     ：侯耀祖
 * @ Description：
 */
public class reverseStr {
    public String reverseStr(String s, int k) {
        int len = s.length();
        int start = 0;
        int stay = len % (2 * k);
        char[] charArray = s.toCharArray();
        for (int i = 0; i < charArray.length; i += 2*k) {
            start = i;
            if (charArray.length-1 < start + k -1){
                reverseString(charArray, stay, len- stay);
            }else {
                reverseString(charArray, k, start);
            }
        }
        return String.copyValueOf(charArray);
    }
    public void reverseString(char[] s, int k, int start) {
        int left = start;
        int right = start + k - 1 ;
        char temp;
        while (left < right){
            temp = s[left];
            s[left] = s[right];
            s[right] = temp;
            left++;
            right--;
        }
    }
}
